<?php
require_once 'google-api-php-client/vendor/autoload.php';

require_once 'google-api-php-client/src/Google/Client.php';
require_once 'google-api-php-client/src/Google/Service.php';
require_once 'google-api-php-client/vendor/google/apiclient-services/src/Google/Service/YouTube.php';
class Youtube {
	public $DEVELOPER_KEY = "AIzaSyAFrr3AXflGs7oSlVH9H3i1JRLCJUJjOXo";
	public $client;
	public $youtube;
	public $channelSectionContentDetails;
	protected static $_instance = null;
	
	// Valid section types.
	public $SECTION_TYPES = array (
			"allPlaylists",
			"completedEvents",
			"likedPlaylists",
			"likes",
			"liveEvents",
			"multipleChannels",
			"multiplePlaylists",
			"popularUploads",
			"recentActivity",
			"recentPosts",
			"recentUploads",
			"singlePlaylist",
			"upcomingEvents" 
	);
	
	// Valid section styles.
	public $SECTION_STYLES = array (
			"horizontalRow",
			"verticalList" 
	);
	public static function getInstance() {
		if (self::$_instance === null) {
			self::$_instance = new self ();
		}
		return self::$_instance;
	}
	public function __construct() {
		$this->client = new Google_Client ();
		$this->client->setDeveloperKey ( $this->DEVELOPER_KEY );
		$this->youtube = new Google_Service_YouTube ( $this->client );
		$this->channelSectionContentDetails = new Google_Service_YouTube_ChannelSectionContentDetails ();
	}
	
	/**
	 * $regionCodeTag
	 * orderByTag 0 relevance 1 viewCount 2 rating 3 date
	 * searchTypeTag 0 video 搜索 1 channel 搜索 2 playlist搜索
	 *
	 * @param unknown_type $keywords        	
	 * @param unknown_type $MAX_RESULTS        	
	 * @return multitype:
	 */
	public function searchVideos($regionCodeTag, $orderByTag, $searchTypeTag, $keywords, $nextPageToken = "", $MAX_RESULTS = 20, $videoDuration = 4) {
		$searchType = "video";
		if ($searchTypeTag == 1) {
			$searchType = "channel";
		} else if ($searchTypeTag == 2) {
			$searchType = "playlist";
		}
		$orderBy = '';
		if ($orderByTag == 1) {
			$orderBy = "viewCount";
		} else if ($orderByTag == 2) {
			$orderBy = "rating";
		} else if ($orderByTag == 3) {
			$orderBy = "date";
		} else if ($orderByTag == 4) {
			$orderBy = "relevance";
		} else if ($orderByTag == 5) {
			$orderBy = "title";
		} else if ($orderByTag == 6) { // 这个没什么必要
			$orderBy = "videoCount";
		}
		
		$arraySearchingCondition = array (
				'q' => $keywords,
				'maxResults' => $MAX_RESULTS,
				'type' => $searchType 
		);
		if (! empty ( $nextPageToken ))
			$arraySearchingCondition ['pageToken'] = $nextPageToken;
		if (! empty ( $orderBy ))
			$arraySearchingCondition ['order'] = $orderBy;
		if (! empty ( $regionCodeTag ))
			$arraySearchingCondition ['regionCode'] = $regionCodeTag;
		if (! empty ( $videoDuration )) {
			if ($videoDuration == 1) {
				$arraySearchingCondition ['videoDuration'] = "long"; // long – Only
				                                                     // include videos
				                                                     // longer than 20
				                                                     // minutes.
			} else if ($videoDuration == 2) {
				$arraySearchingCondition ['videoDuration'] = "medium"; // medium –
				                                                       // Only include
				                                                       // videos that are
				                                                       // between four and
				                                                       // 20 minutes long
				                                                       // (inclusive).
			} else if ($videoDuration == 3) {
				$arraySearchingCondition ['videoDuration'] = "short"; // short –
				                                                      // Only include videos
				                                                      // that are less than
				                                                      // four minutes long.
			} else {
				$arraySearchingCondition ['videoDuration'] = "any"; // any – Do not
				                                                    // filter video search
				                                                    // results based on
				                                                    // their duration. This
				                                                    // is the default value.
			}
		}
		// var_dump($arraySearchingCondition);
		// video, channel, playlist
		$searchResponse = $this->youtube->search->listSearch ( 'id,snippet', $arraySearchingCondition );
		$arr = $this->insertVideoArray ( $searchResponse );
		
		return $arr;
	}
	
	/**
	 * $regionCodeTag
	 * orderByTag 0 relevance 1 viewCount 2 rating 3 date
	 * searchTypeTag 0 video 搜索 1 channel 搜索 2 playlist搜索
	 *
	 * @param unknown_type $keywords        	
	 * @param unknown_type $MAX_RESULTS        	
	 * @return multitype:
	 */
	public function searchVideosByCId($videoCategoryId, $regionCodeTag, $orderByTag, $searchTypeTag, $nextPageToken = "", $MAX_RESULTS = 20, $videoDuration = 4) {
		$searchType = "video";
		if ($searchTypeTag == 1) {
			$searchType = "channel";
		} else if ($searchTypeTag == 2) {
			$searchType = "playlist";
		}
		$orderBy = '';
		if ($orderByTag == 1) {
			$orderBy = "viewCount";
		} else if ($orderByTag == 2) {
			$orderBy = "rating";
		} else if ($orderByTag == 3) {
			$orderBy = "date";
		} else if ($orderByTag == 4) {
			$orderBy = "relevance";
		} else if ($orderByTag == 5) {
			$orderBy = "title";
		} else if ($orderByTag == 6) { // 这个没什么必要
			$orderBy = "videoCount";
		}
		
		$arraySearchingCondition = array (
				'q' => $keywords,
				'maxResults' => $MAX_RESULTS,
				'type' => $searchType,
				'videoCategoryId' => $videoCategoryId 
		);
		if (! empty ( $nextPageToken ))
			$arraySearchingCondition ['pageToken'] = $nextPageToken;
		if (! empty ( $orderBy ))
			$arraySearchingCondition ['order'] = $orderBy;
		if (! empty ( $regionCodeTag ))
			$arraySearchingCondition ['regionCode'] = $regionCodeTag;
		if (! empty ( $videoDuration )) {
			if ($videoDuration == 1) {
				$arraySearchingCondition ['videoDuration'] = "long"; // long – Only
				                                                     // include videos
				                                                     // longer than 20
				                                                     // minutes.
			} else if ($videoDuration == 2) {
				$arraySearchingCondition ['videoDuration'] = "medium"; // medium –
				                                                       // Only include
				                                                       // videos that are
				                                                       // between four and
				                                                       // 20 minutes long
				                                                       // (inclusive).
			} else if ($videoDuration == 3) {
				$arraySearchingCondition ['videoDuration'] = "short"; // short –
				                                                      // Only include videos
				                                                      // that are less than
				                                                      // four minutes long.
			} else {
				$arraySearchingCondition ['videoDuration'] = "any"; // any – Do not
				                                                    // filter video search
				                                                    // results based on
				                                                    // their duration. This
				                                                    // is the default value.
			}
		}
		
		// var_dump($arraySearchingCondition);
		// video, channel, playlist
		$searchResponse = $this->youtube->search->listSearch ( 'id,snippet', $arraySearchingCondition );
		$arr = $this->insertVideoArray ( $searchResponse );
		
		return $arr;
	}
	
	/**
	 * $regionCodeTag
	 * orderByTag 0 relevance 1 viewCount 2 rating 3 date
	 * searchTypeTag 0 video 搜索 1 channel 搜索 2 playlist搜索
	 *
	 * @param unknown_type $keywords
	 * @param unknown_type $MAX_RESULTS
	 * @return multitype:
	 */
	public function searchVideosByRelateVID($vid, $regionCodeTag, $orderByTag, $searchTypeTag, $nextPageToken = "", $MAX_RESULTS = 20, $videoDuration = 4) {
		$searchType = "video";
		if ($searchTypeTag == 1) {
			$searchType = "channel";
		} else if ($searchTypeTag == 2) {
			$searchType = "playlist";
		}
		$orderBy = '';
		if ($orderByTag == 1) {
			$orderBy = "viewCount";
		} else if ($orderByTag == 2) {
			$orderBy = "rating";
		} else if ($orderByTag == 3) {
			$orderBy = "date";
		} else if ($orderByTag == 4) {
			$orderBy = "relevance";
		} else if ($orderByTag == 5) {
			$orderBy = "title";
		} else if ($orderByTag == 6) { // 这个没什么必要
			$orderBy = "videoCount";
		}
	
		$arraySearchingCondition = array (
				'maxResults' => $MAX_RESULTS,
				'type' => $searchType,
				'relatedToVideoId' => $vid
		);
		if (! empty ( $nextPageToken ))
			$arraySearchingCondition ['pageToken'] = $nextPageToken;
		if (! empty ( $orderBy ))
			$arraySearchingCondition ['order'] = $orderBy;
		if (! empty ( $regionCodeTag ))
			$arraySearchingCondition ['regionCode'] = $regionCodeTag;
		if (! empty ( $videoDuration )) {
			if ($videoDuration == 1) {
				$arraySearchingCondition ['videoDuration'] = "long"; // long – Only
				// include videos
				// longer than 20
				// minutes.
			} else if ($videoDuration == 2) {
				$arraySearchingCondition ['videoDuration'] = "medium"; // medium –
				// Only include
				// videos that are
				// between four and
				// 20 minutes long
				// (inclusive).
			} else if ($videoDuration == 3) {
				$arraySearchingCondition ['videoDuration'] = "short"; // short –
				// Only include videos
				// that are less than
				// four minutes long.
			} else {
				$arraySearchingCondition ['videoDuration'] = "any"; // any – Do not
				// filter video search
				// results based on
				// their duration. This
				// is the default value.
			}
		}
	
		// var_dump($arraySearchingCondition);
		// video, channel, playlist
		$searchResponse = $this->youtube->search->listSearch ( 'id,snippet', $arraySearchingCondition );
		$arr = $this->insertVideoArray ( $searchResponse );
	
		return $arr;
	}
	
	/**
	 * $regionCodeTag
	 * orderByTag 0 relevance 1 viewCount 2 rating 3 date
	 * searchTypeTag 0 video 搜索 1 channel 搜索 2 playlist搜索
	 *
	 * @param unknown_type $keywords        	
	 * @param unknown_type $MAX_RESULTS        	
	 * @return multitype:
	 */
	public function searchPlayList($regionCodeTag, $orderByTag, $keywords, $nextPageToken = "", $MAX_RESULTS = 20) {
		$searchType = "playlist";
		$orderBy = '';
		if ($orderByTag == 1) {
			$orderBy = "viewCount";
		} else if ($orderByTag == 2) {
			$orderBy = "rating";
		} else if ($orderByTag == 3) {
			$orderBy = "date";
		} else if ($orderByTag == 4) {
			$orderBy = "relevance";
		} else if ($orderByTag == 5) {
			$orderBy = "title";
		} else if ($orderByTag == 6) { // 这个没什么必要
			$orderBy = "videoCount";
		}
		$arraySearchingCondition = array (
				'q' => $keywords,
				'maxResults' => $MAX_RESULTS,
				'type' => $searchType 
		);
		
		if (! empty ( $nextPageToken ))
			$arraySearchingCondition ['pageToken'] = $nextPageToken;
		if (! empty ( $orderBy ))
			$arraySearchingCondition ['order'] = $orderBy;
		if (! empty ( $regionCodeTag ))
			$arraySearchingCondition ['regionCode'] = $regionCodeTag;
			// var_dump($arraySearchingCondition);
			// video, channel, playlist
		$searchResponse = $this->youtube->search->listSearch ( 'id,snippet', $arraySearchingCondition );
		$arr = Array ();
		// var_dump ( $searchResponse );
		
		foreach ( $searchResponse ['items'] as $searchResult ) {
			$model = Array (
					'playlistid' => $searchResult ['id'] ['playlistId'],
					'nextPageToken' => $searchResponse ['nextPageToken'],
					'regionCode' => $searchResponse ['regionCode'],
					'channelid' => $searchResult ['snippet'] ['channelId'],
					'title' => $searchResult ['snippet'] ['title'],
					'channelTitle' => $searchResult ['snippet'] ['channelTitle'],
					'description' => $searchResult ['snippet'] ['description'],
					'publishedAt' => $searchResult ['snippet'] ['publishedAt'],
					'default' => $searchResult ['snippet'] ['modelData'] ['thumbnails'] ['default'] ['url'],
					'thumnails' => $searchResult ['snippet'] ['modelData'] ['thumbnails'] ['medium'] ['url'],
					'high' => $searchResult ['snippet'] ['modelData'] ['thumbnails'] ['high'] ['url'] 
			);
			array_push ( $arr, $model );
		}
		return $arr;
	}
	
	/**
	 * $regionCodeTag
	 * orderByTag 0 relevance 1 viewCount 2 rating 3 date
	 * searchTypeTag 0 video 搜索 1 channel 搜索 2 playlist搜索
	 *
	 * @param unknown_type $keywords        	
	 * @param unknown_type $MAX_RESULTS        	
	 * @return multitype:
	 */
	public function searchChannel($regionCodeTag, $orderByTag, $keywords, $nextPageToken = "", $MAX_RESULTS = 20) {
		$searchType = "channel";
		$orderBy = '';
		if ($orderByTag == 1) {
			$orderBy = "viewCount";
		} else if ($orderByTag == 2) {
			$orderBy = "rating";
		} else if ($orderByTag == 3) {
			$orderBy = "date";
		} else if ($orderByTag == 4) {
			$orderBy = "relevance";
		} else if ($orderByTag == 5) {
			$orderBy = "title";
		} else if ($orderByTag == 6) { // 这个没什么必要
			$orderBy = "videoCount";
		}
		
		$arraySearchingCondition = array (
				'q' => $keywords,
				'maxResults' => $MAX_RESULTS,
				'type' => $searchType 
		);
		
		if (! empty ( $nextPageToken ))
			$arraySearchingCondition ['pageToken'] = $nextPageToken;
		if (! empty ( $orderBy ))
			$arraySearchingCondition ['order'] = $orderBy;
		if (! empty ( $regionCodeTag ))
			$arraySearchingCondition ['regionCode'] = $regionCodeTag;
			// var_dump($arraySearchingCondition);
			// video, channel, playlist
		$searchResponse = $this->youtube->search->listSearch ( 'id,snippet', $arraySearchingCondition );
		$arr = Array ();
		// var_dump ( $searchResponse );
		
		foreach ( $searchResponse ['items'] as $searchResult ) {
			$model = Array (
					'nextPageToken' => $searchResponse ['nextPageToken'],
					'regionCode' => $searchResponse ['regionCode'],
					'channelid' => $searchResult ['snippet'] ['channelId'],
					'title' => $searchResult ['snippet'] ['title'],
					'channelTitle' => $searchResult ['snippet'] ['channelTitle'],
					'description' => $searchResult ['snippet'] ['description'],
					'publishedAt' => $searchResult ['snippet'] ['publishedAt'],
					'default' => $searchResult ['snippet'] ['modelData'] ['thumbnails'] ['default'] ['url'],
					'medium' => $searchResult ['snippet'] ['modelData'] ['thumbnails'] ['medium'] ['url'],
					'high' => $searchResult ['snippet'] ['modelData'] ['thumbnails'] ['high'] ['url'] 
			);
			array_push ( $arr, $model );
		}
		return $arr;
	}
	
	/**
	 * 搜索相关video
	 *
	 * @param unknown_type $relateVideoId        	
	 * @param unknown_type $MAX_RESULTS        	
	 * @return multitype:
	 */
	public function getRelateVideos($relateVideoId, $MAX_RESULTS) {
		$arraySearchingCondition = array (
				'maxResults' => $MAX_RESULTS,
				'relatedToVideoId' => $relateVideoId,
				'type' => 'video' 
		);
		
		// video, channel, playlist
		$searchResponse = $this->youtube->search->listSearch ( 'id,snippet', $arraySearchingCondition );
		$arr = $this->insertVideoArray ( $searchResponse );
		
		return $arr;
	}
	
	/**
	 * 获取 相关video详细信息
	 *
	 * @param unknown_type $relateVideoId        	
	 * @param unknown_type $MAX_RESULTS        	
	 * @return multitype:
	 */
	public function getContentDetail($videoId) {
		$arraySearchingCondition = array (
				'id' => $videoId 
		);
		
		$searchResponse = $this->youtube->videos->listVideos ( 'snippet,contentDetails,statistics,status', $arraySearchingCondition );
		$model = Array (
				'vid' => $videoId,
				'publishedAt' => $searchResponse ['items'] [0] ['modelData'] ['snippet'] ['publishedAt'],
				'channelId' => $searchResponse ['items'] [0] ['modelData'] ['snippet'] ['channelId'],
				'title' => $searchResponse ['items'] [0] ['modelData'] ['snippet'] ['title'],
				'description' => $searchResponse ['items'] [0] ['modelData'] ['snippet'] ['description'],
				'channelTitle' => $searchResponse ['items'] [0] ['modelData'] ['snippet'] ['channelTitle'],
				'tags' => $searchResponse ['items'] [0] ['modelData'] ['snippet'] ['tags'],
				'categoryId' => $searchResponse ['items'] [0] ['modelData'] ['snippet'] ['categoryId'],
				'default' => $searchResponse ['items'] [0] ['modelData'] ['snippet'] ['thumbnails'] ['default'],
				'medium' => $searchResponse ['items'] [0] ['modelData'] ['snippet'] ['thumbnails'] ['medium'],
				'high' => $searchResponse ['items'] [0] ['modelData'] ['snippet'] ['thumbnails'] ['high'],
				'standard' => $searchResponse ['items'] [0] ['modelData'] ['snippet'] ['thumbnails'] ['standard'],
				'maxres' => $searchResponse ['items'] [0] ['modelData'] ['snippet'] ['thumbnails'] ['maxres'],
				'localizedTitle' => $searchResponse ['items'] [0] ['modelData'] ['snippet'] ['localized'] ['title'],
				'localizeddescription' => $searchResponse ['items'] [0] ['modelData'] ['snippet'] ['localized'] ['description'],
				'duration' => $searchResponse ['items'] [0] ['modelData'] ['contentDetails'] ['duration'],
				'dimension' => $searchResponse ['items'] [0] ['modelData'] ['contentDetails'] ['dimension'],
				'definition' => $searchResponse ['items'] [0] ['modelData'] ['contentDetails'] ['definition'],
				
				'viewCount' => $searchResponse ['items'] [0] ['modelData'] ['statistics'] ['viewCount'],
				'likeCount' => $searchResponse ['items'] [0] ['modelData'] ['statistics'] ['likeCount'],
				'dislikeCount' => $searchResponse ['items'] [0] ['modelData'] ['statistics'] ['dislikeCount'],
				'favoriteCount' => $searchResponse ['items'] [0] ['modelData'] ['statistics'] ['favoriteCount'],
				'commentCount' => $searchResponse ['items'] [0] ['modelData'] ['statistics'] ['commentCount'] 
		);
		var_dump ( $model );
		return $model;
	}
	
	/**
	 *
	 * @param
	 *        	searchResponse
	 */
	private function insertVideoArray($searchResponse) {
		// 与vid 相关的
		// relatedToVideoId=wtLJPvx7-ys
		// 提取最受欢迎的video
		/*
		 *
		 * https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?
		 * part=snippet &chart=mostPopular &regionCode=es //国家缩写
		 * &videoCategoryId=17
		 */
		// 通过region来搜索
		// 详细国家缩写请看链接https://developers.google.com/youtube/2.0/developers_guide_protocol_video_feeds#Region_specific_feeds
		// http://gdata.youtube.com/feeds/api/standardfeeds/regionID/most_popular?v=2
		$arr = Array ();
		// var_dump ( $searchResponse );
		
		foreach ( $searchResponse ['items'] as $searchResult ) {
			// var_dump($searchResult['snippet']);
			// var_dump($searchResult['id']);
			switch ($searchResult ['id'] ['kind']) { // 就是youtube 的频道id
				case 'youtube#video' :
					// var_dump ( $searchResult ['snippet'] );
					$model = Array (
							'vid' => $searchResult ['id'] ['videoId'],
							'nextPageToken' => $searchResponse ['nextPageToken'],
							'totalResults' => $searchResponse ['pageInfo'] ['totalResults'],
							'resultsPerPage' => $searchResponse ['pageInfo'] ['resultsPerPage'],
							'regionCode' => $searchResponse ['regionCode'],
							'channelid' => $searchResult ['snippet'] ['channelId'],
							'title' => $searchResult ['snippet'] ['title'],
							'channelTitle' => $searchResult ['snippet'] ['channelTitle'],
							'description' => $searchResult ['snippet'] ['description'],
							'publishedAt' => $searchResult ['snippet'] ['publishedAt'],
							'default' => $searchResult ['snippet'] ['modelData'] ['thumbnails'] ['default'] ['url'],
							'medium' => $searchResult ['snippet'] ['modelData'] ['thumbnails'] ['medium'] ['url'],
							'high' => $searchResult ['snippet'] ['modelData'] ['thumbnails'] ['high'] ['url'] 
					);
					array_push ( $arr, $model );
					break;
			}
		}
		return $arr;
	}
	
	/**
	 * 获取 相关video 评论信息
	 *
	 * @param unknown_type $relateVideoId        	
	 * @param unknown_type $MAX_RESULTS        	
	 * @return multitype:
	 */
	public function getCommentsThread($videoId, $nextPageToken) {
		$arraySearchingCondition = array (
				'videoId' => $videoId,
				'maxResults' => 100 
		);
		if (! empty ( $nextPageToken ))
			$arraySearchingCondition ['nextPageToken'] = $nextPageToken;
		$searchResponse = $this->youtube->commentThreads->listCommentThreads ( 'snippet', $arraySearchingCondition );
		$arr = Array ();
		
		foreach ( $searchResponse ['modelData'] ['items'] as $searchResult ) {
			$model = Array (
					'cid' => $searchResult ['id'],
					'nextPageToken' => $searchResponse ['nextPageToken'],
					'authorDisplayName' => $searchResult ['snippet'] ['topLevelComment'] ['snippet'] ['authorDisplayName'],
					'authorProfileImageUrl' => $searchResult ['snippet'] ['topLevelComment'] ['snippet'] ['authorProfileImageUrl'],
					'authorChannelUrl' => $searchResult ['snippet'] ['topLevelComment'] ['snippet'] ['authorChannelUrl'],
					'authorChannelId' => $searchResult ['snippet'] ['topLevelComment'] ['snippet'] ['authorChannelId'] [0] ['value'],
					'videoId' => $searchResult ['snippet'] ['topLevelComment'] ['snippet'] ['videoId'],
					'textDisplay' => $searchResult ['snippet'] ['topLevelComment'] ['snippet'] ['textDisplay'],
					'textOriginal' => $searchResult ['snippet'] ['topLevelComment'] ['snippet'] ['textOriginal'],
					'canRate' => $searchResult ['snippet'] ['topLevelComment'] ['snippet'] ['canRate'],
					'viewerRating' => $searchResult ['snippet'] ['topLevelComment'] ['snippet'] ['viewerRating'],
					'likeCount' => $searchResult ['snippet'] ['topLevelComment'] ['snippet'] ['likeCount'],
					'publishedAt' => $searchResult ['snippet'] ['topLevelComment'] ['snippet'] ['publishedAt'],
					'updatedAt' => $searchResult ['snippet'] ['topLevelComment'] ['snippet'] ['updatedAt'] 
			);
			array_push ( $arr, $model );
		}
		return $arr;
	}
	
	/**
	 * 获取 channel 信息
	 *
	 * @param unknown_type $relateVideoId        	
	 * @param unknown_type $MAX_RESULTS        	
	 * @return multitype:
	 */
	public function getChannels($channelId, $language) {
		$arraySearchingCondition = array (
				'id' => $channelId 
		);
		if (! empty ( $language ))
			$arraySearchingCondition ['hl'] = $language;
		$searchResponse = $this->youtube->channels->listChannels ( ' snippet, contentDetails, statistics, topicDetails, status, brandingSettings, localizations, invideoPromotion', $arraySearchingCondition );
		var_dump ( $searchResponse );
		// var_dump($searchResponse['modelData']['items'][0]);
		/*
		 * $model = Array ( 'channelid' => $channelId, 'title' =>
		 * $searchResponse ['modelData'] ['items'] [0] ['snippet'] ['title'],
		 * 'description' => $searchResponse ['modelData'] ['items'] [0]
		 * ['snippet'] ['description'], 'customUrl' => $searchResponse
		 * ['modelData'] ['items'] [0] ['snippet'] ['customUrl'], 'publishedAt'
		 * => $searchResponse ['modelData'] ['items'] [0] ['snippet']
		 * ['publishedAt'], 'default' => $searchResponse ['modelData'] ['items']
		 * [0] ['snippet'] ['thumbnails'] ['default'], 'medium' =>
		 * $searchResponse ['modelData'] ['items'] [0] ['snippet']
		 * ['thumbnails'] ['medium'], 'high' => $searchResponse ['modelData']
		 * ['items'] [0] ['snippet'] ['thumbnails'] ['high'], 'localizedTitle'
		 * => $searchResponse ['modelData'] ['items'] [0] ['snippet']
		 * ['localized'] ['title'], 'localizedDescription' => $searchResponse
		 * ['modelData'] ['items'] [0] ['snippet'] ['localized']
		 * ['description'], 'viewCount' => $searchResponse ['modelData']
		 * ['items'] [0] ['statistics'] ['viewCount'], 'commentCount' =>
		 * $searchResponse ['modelData'] ['items'] [0] ['statistics']
		 * ['commentCount'], 'subscriberCount' => $searchResponse ['modelData']
		 * ['items'] [0] ['statistics'] ['subscriberCount'], 'videoCount' =>
		 * $searchResponse ['modelData'] ['items'] [0] ['statistics']
		 * ['videoCount'], 'image' => $searchResponse ['modelData'] ['items']
		 * [0] ['brandingSettings'] ['image'] );
		 */
		return $model;
	}
	
	/**
	 * 获取 相关video 评论信息
	 * 没什么用了
	 *
	 * @param unknown_type $relateVideoId        	
	 * @param unknown_type $MAX_RESULTS        	
	 * @return multitype:
	 */
	public function getChannelSections($channelId) {
		$arraySearchingCondition = array (
				'channelId' => $channelId 
		);
		$searchResponse = $this->youtube->channelSections->listChannelSections ( 'snippet, contentDetails', $arraySearchingCondition );
		$arr = Array ();
		
		// var_dump($searchResponse['modelData']['items']);
		
		var_dump ( $searchResponse ['modelData'] ['items'] [0] ['snippet'] );
		var_dump ( $searchResponse ['modelData'] ['items'] [0] ['contentDetails'] );
		echo "11111111111111111";
		var_dump ( $searchResponse ['modelData'] ['items'] [1] ['snippet'] );
		var_dump ( $searchResponse ['modelData'] ['items'] [1] ['contentDetails'] );
		echo "22222222222222222";
		var_dump ( $searchResponse ['modelData'] ['items'] [2] ['snippet'] );
		var_dump ( $searchResponse ['modelData'] ['items'] [2] ['contentDetails'] );
		echo "33333333333333333";
		var_dump ( $searchResponse ['modelData'] ['items'] [3] ['snippet'] );
		var_dump ( $searchResponse ['modelData'] ['items'] [3] ['contentDetails'] );
	}
	
	/**
	 * 通过channel获取playlist 感觉比 channelsection要好
	 *
	 * @param unknown_type $relateVideoId        	
	 * @param unknown_type $MAX_RESULTS        	
	 * @return multitype:
	 */
	public function getPlayLists($channelId) {
		$arraySearchingCondition = array (
				'channelId' => $channelId,
				'maxResults' => 50 
		);
		$searchResponse = $this->youtube->playlists->listPlaylists ( 'snippet, contentDetails', $arraySearchingCondition );
		return $searchResponse ['modelData'] ['items'];
	}
	
	/**
	 * 通过regionCode
	 *
	 * @param unknown_type $relateVideoId        	
	 * @param unknown_type $MAX_RESULTS        	
	 * @return multitype:
	 */
	public function getVideoCatoriesList($regionCode) {
		$arraySearchingCondition = array (
				'regionCode' => 'US' 
		);
		$searchResponse = $this->youtube->videoCategories->listVideoCategories ( 'snippet', $arraySearchingCondition );
		// var_dump($searchResponse['modelData']['items']);
		// var_dump($searchResponse['modelData']['items']);
		return $searchResponse ['modelData'] ['items'];
	}
	
	public function getLanguages() {
		$arraySearchingCondition = array (
		);
		$searchResponse = $this->youtube->$i18nLanguages->listVideoCategories ( 'snippet', $arraySearchingCondition );
		// var_dump($searchResponse['modelData']['items']);
		// var_dump($searchResponse['modelData']['items']);
		var_dump($searchResponse);
// 		return $searchResponse ['modelData'] ['items'];
		
	}
}
?>